home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
nqdir.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-10-25
|
4KB
|
169 lines
/*
NQDIR.C Aad Slingerland, oktober 1989
Arnhem, The Netherlands.
Utility to check for the existance of a specified directory
on a network drive. The specified directory does not have to
contain any files. This program returns an errorlevel to a
batch file and in case the directory does not exist, a message
to the user.
Location: SYS:PUBLIC
Attributes: Shareable Readonly
Invokation: Batch file or interactive
Syntax: NQDIR d:\path [/D]
The /D option gives debug information about
various API calls.
Return codes: 0 directory exists
1 directory not found
2 invalid command syntax
*/
/*
Macro definitions
*/
#define MSC /* For the netware PROLOG.H */
/*
Header files included
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <nit.h>
/*
Function prototypes for local functions
*/
void TellThemHow (void);
/*
Main line
*/
main (argc, argv)
int argc;
char *argv[];
{
/*
Local variables
*/
int x = 0;
int y = 0;
int debug = 0;
BYTE dNum;
BYTE dirHandle;
BYTE sFlags;
WORD conID;
char oldPath[255];
char newPath[255];
char *z;
/*
Check for valid command line parameters
*/
if (argc == 1)
{
TellThemHow ();
return (2);
}
if ( ! isalpha (*argv[1]))
{
TellThemHow ();
return (2);
}
if (( *(argv[1] + 1) != ':') || ( *(argv[1] + 2) != '\\'))
{
TellThemHow ();
return (2);
}
if (argc == 3)
if (toupper ( *(argv[2] + 1)) == 'D')
debug++;
else
{
TellThemHow ();
return (2);
}
/*
Convert the drive letter to a number, where
drive A = 0, B = 1 etc.
*/
dNum = toupper (*argv[1]) - 65;
/*
Get the directory handle for the specified drive.
*/
sFlags = GetDriveInformation (dNum, &conID, &dirHandle);
if (debug)
{
printf ("\n");
printf ("Shell function : GetDriveInformation\n");
printf ("Statusflags : %d\n", sFlags);
printf ("ConnectionID : %d\n", conID);
printf ("DirectoryHandle : %d\n", dirHandle);
}
/*
Get the current directory path for the specified handle.
*/
x = GetDirectoryPath (dirHandle, oldPath);
if (debug)
{
printf ("\n");
printf ("Shell function : GetDirectoryPath\n");
printf ("returncode : %d\n", x);
printf ("Current Path : %s\n", oldPath);
}
/*
Build a the newPath string, because it must
start with a volume name, not a drive letter.
*/
z = strchr (oldPath, ':');
x = z - oldPath + 1;
strncpy (newPath, oldPath, x);
newPath[x] = '\0';
strcat (newPath, argv[1] + 3);
/*
Set a new directory (command line parm) to this
handle. If oke, the directory exists.
*/
x = SetDirectoryHandle (dirHandle, newPath, dirHandle);
if (debug)
{
printf ("\n");
printf ("Shell function : SetDirectoryHandle\n");
printf ("New specified path : %s\n", newPath);
printf ("returncode : %d\n", x);
}
if (x == 0)
{
/*
Restore old path again
*/
y = SetDirectoryHandle (dirHandle, oldPath, dirHandle);
if (debug)
{
printf ("\n");
printf ("Shell function : SetDirectoryHandle\n");
printf ("New specified path : %s\n", oldPath);
printf ("returncode : %d\n", x);
}
}
else
{
printf ("\nDirectory %s does not exist.\n", argv[1]);
return (1);
}
return (0);
}
/*
In case of an invalid command line syntax.
*/
void TellThemHow (void)
{
printf ("\nThe correct syntax for the NQDIR command is : ");
printf ("NQDIR d:\\path [/d]\n");
printf ("The optional parameter /d gives status information\n");
printf ("about every function call to the Netware Shell.\n");
}